home *** CD-ROM | disk | FTP | other *** search
- import java.io.IOException;
- import javax.microedition.lcdui.Canvas;
- import javax.microedition.lcdui.Graphics;
- import javax.microedition.lcdui.Image;
-
- public class ChessGUI {
- public static final int MAX_COMMANDS = 2;
- private static final int LINE_CORR = 1;
- private static final int BACKGROUND = 12439485;
- private static final int STRINGHEIGHT = 24;
- private Canvas canvas;
- private Image chessimg;
- private Graphics chessgraph;
- private Image[] pieces;
- private String[] commands;
-
- public ChessGUI(Canvas var1) {
- this.canvas = var1;
- this.initializeImage("/xboard.png");
- this.commands = new String[3];
-
- for(int var2 = 1; var2 <= 2; ++var2) {
- this.commands[var2] = "";
- }
-
- }
-
- private void createSubImages(Image var1) {
- this.pieces = new Image[28];
- int var3 = var1.getWidth() / 8;
- int var4 = var1.getHeight() / 8;
-
- for(int var6 = 0; var6 < 28; ++var6) {
- byte var2 = 11;
- switch (var6) {
- case 0:
- var2 = 26;
- break;
- case 1:
- var2 = 17;
- break;
- case 2:
- var2 = 88;
- break;
- case 3:
- var2 = 28;
- break;
- case 4:
- var2 = 68;
- break;
- case 5:
- var2 = 48;
- break;
- case 6:
- var2 = 55;
- break;
- case 7:
- var2 = 16;
- break;
- case 8:
- var2 = 27;
- break;
- case 9:
- var2 = 18;
- break;
- case 10:
- var2 = 78;
- break;
- case 11:
- var2 = 38;
- break;
- case 12:
- var2 = 45;
- break;
- case 13:
- var2 = 58;
- break;
- case 14:
- var2 = 13;
- break;
- case 15:
- var2 = 22;
- break;
- case 16:
- var2 = 11;
- break;
- case 17:
- var2 = 71;
- break;
- case 18:
- var2 = 31;
- break;
- case 19:
- var2 = 44;
- break;
- case 20:
- var2 = 51;
- break;
- case 21:
- var2 = 23;
- break;
- case 22:
- var2 = 12;
- break;
- case 23:
- var2 = 81;
- break;
- case 24:
- var2 = 21;
- break;
- case 25:
- var2 = 61;
- break;
- case 26:
- var2 = 41;
- break;
- case 27:
- var2 = 54;
- }
-
- this.pieces[var6] = Image.createImage(var3 - 2, var4 - 2);
- Graphics var5 = this.pieces[var6].getGraphics();
- var5.drawImage(var1, -1 - this.getXPos(var2), -1 - this.getYPos(var2), 20);
- }
-
- }
-
- public void drawChessGraphics(Graphics var1) {
- var1.drawImage(this.chessimg, this.canvas.getWidth() - this.chessimg.getWidth(), 0, 20);
- }
-
- public void drawCommands(Graphics var1) {
- int var2 = this.chessimg.getHeight() / 8;
- var1.setColor(12439485);
- var1.fillRect(0, 0, this.canvas.getWidth() - this.chessimg.getWidth(), this.chessimg.getHeight());
- var1.setColor(0, 0, 0);
-
- for(int var3 = 0; var3 < 4; ++var3) {
- if (this.commands[1].length() > var3) {
- var1.drawChar(this.commands[1].charAt(var3), 5, var3 * var2, 20);
- }
- }
-
- var1.drawLine(0, 4 * var2 - 2, this.canvas.getWidth() - this.chessimg.getWidth(), 4 * var2 - 2);
- var1.drawLine(0, 4 * var2 - 1, this.canvas.getWidth() - this.chessimg.getWidth(), 4 * var2 - 1);
-
- for(int var4 = 0; var4 < 4; ++var4) {
- if (this.commands[2].length() > var4) {
- var1.drawChar(this.commands[2].charAt(var4), 5, (var4 + 4) * var2, 20);
- }
- }
-
- var1.drawLine(0, this.chessimg.getHeight() - 2, this.canvas.getWidth() - this.chessimg.getWidth(), this.chessimg.getHeight() - 2);
- var1.drawLine(0, this.chessimg.getHeight() - 1, this.canvas.getWidth() - this.chessimg.getWidth(), this.chessimg.getHeight() - 1);
- }
-
- public boolean drawInformation(Graphics var1, int var2, String var3) {
- var1.setColor(12439485);
- var1.fillRect(0, (var2 - 1) * 24 + this.chessimg.getHeight(), this.canvas.getWidth(), 24);
- var1.setColor(0, 0, 0);
- var1.drawString(var3, 5, (var2 - 1) * 24 + this.chessimg.getHeight(), 20);
- return true;
- }
-
- public void drawPiece(Graphics var1, int var2, int var3, int var4) {
- int var5 = var4 / 10 + var4 % 10;
- byte var6;
- if (var5 % 2 == 0) {
- var6 = 0;
- } else {
- var6 = 1;
- }
-
- var5 = var3 * 14 + var6 * 7 + var2;
- var1.drawImage(this.pieces[var5], this.getXPos(var4) + 1, this.getYPos(var4) + 1, 20);
- }
-
- public void drawPiece(Graphics var1, int var2, int var3, int var4, int var5, int var6) {
- int var7 = var3 * 14 + var4 * 7 + var2;
- var1.drawImage(this.pieces[var7], var5, var6, 20);
- }
-
- public Graphics getChessGraphics() {
- return this.chessgraph;
- }
-
- public int getCommand(int var1, int var2) {
- int var3 = this.chessimg.getHeight() / 8;
- if (var1 < this.canvas.getWidth() - this.chessimg.getWidth()) {
- if (var2 < 4 * var3) {
- return 1;
- } else {
- return var2 < 8 * var3 ? 2 : 0;
- }
- } else {
- return 0;
- }
- }
-
- public String getCommandName(int var1) {
- return this.commands[var1];
- }
-
- public int getFieldCode(int var1, int var2) {
- int var3 = var1 - (this.canvas.getWidth() - this.chessimg.getWidth());
- int var4 = (var3 / (this.chessimg.getWidth() / 8) + 1) * 10;
- var4 += (this.chessimg.getHeight() - var2) / (this.chessimg.getHeight() / 8) + 1;
- return var4;
- }
-
- private int getXPos(int var1) {
- return (var1 / 10 - 1) * (this.chessimg.getWidth() / 8);
- }
-
- private int getYPos(int var1) {
- return this.chessimg.getHeight() - var1 % 10 * this.chessimg.getHeight() / 8;
- }
-
- public boolean inChessBoard(int var1, int var2) {
- return var1 > this.canvas.getWidth() - this.chessimg.getWidth() && var2 < this.chessimg.getHeight();
- }
-
- public boolean initializeImage(String var1) {
- try {
- this.chessimg = Image.createImage("/xboard.png");
- this.createSubImages(this.chessimg);
- Image var2 = this.chessimg;
- this.chessimg = Image.createImage(var2.getWidth(), var2.getHeight());
- this.chessgraph = this.chessimg.getGraphics();
- this.chessgraph.drawImage(var2, 0, 0, 20);
- return true;
- } catch (IOException var3) {
- CU.shout("initializeImage error" + ((Throwable)var3).toString());
- return false;
- }
- }
-
- public boolean registerCommand(int var1, String var2) {
- if (var1 >= 1 && var1 <= 2) {
- this.commands[var1] = var2;
- return true;
- } else {
- return false;
- }
- }
-
- public void selectField(Graphics var1, int var2, int var3, int var4, int var5, boolean var6) {
- int var7 = var1.getColor();
- var1.setColor(var3, var4, var5);
- int var8 = this.getXPos(var2);
- int var9 = this.getYPos(var2);
- if (var6) {
- var1.fillArc(var8 + 3, var9 + 1, this.chessimg.getWidth() / 8 - 5, this.chessimg.getHeight() / 8 - 4, 0, 360);
- } else {
- var1.drawArc(var8 + 3, var9 + 1, this.chessimg.getWidth() / 8 - 5, this.chessimg.getHeight() / 8 - 4, 0, 360);
- }
-
- var1.setColor(var7);
- }
- }
-